import { ADD_COUNTER, ADD_CARTITEM } from './mutation-types';

import { StorageFn } from 'common/storage'
const storage = new StorageFn()
export default {
  [ADD_COUNTER](state,prod){
    prod.count ++
  },
  [ADD_CARTITEM](state,prod){
    state.cartList.push(prod)
    
  },
  toggleStatus(state,iid){
    let list = state.cartList.map(item => {
      if(item.iid === iid){
        item.iid = iid
      }
      return item;
    })
    storage.setLocal('cartList',list)
  },
  checkedAll(state){
    let list = state.cartList.map(item=>{
      item.checked = false;
      return item
    })
    storage.setLocal('cartList',list)
    
  },
  deCheckedAll(state){
    let list = state.cartList.map(item=>{
      item.checked = true
      return item;
    })
    storage.setLocal('cartList',list)
  },
  delGoodsItem(state,payload){
    state.cartList.forEach((item,index)=>{
      if(item.iid == payload.iid) {
        state.cartList.splice(index,1)
        payload.fn('删除成功')
      }   
    })
  }
}